<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" pageEncoding="UTF-8" %>
<!DOCTYPE html >
<html>
<head>
    <base href="${base}/"/>
    <title>后台管理</title>
    <meta charset="utf-8"/>
    <link rel="stylesheet" href="css/admin.css"/>
    <style>
        /* 用户列表样式 */
        .search_form {
            margin-bottom: 20px;
            padding: 15px;
            background-color: #f9f9f9;
            border-radius: 5px;
        }
        
        .list_table {
            width: 100%;
            overflow-x: auto;
        }
        
        .list_table table {
            width: 100%;
            border-collapse: collapse;
        }
        
        .list_table th, .list_table td {
            padding: 10px;
            text-align: center;
            border: 1px solid #ddd;
        }
        
        .list_table th {
            background-color: #f2f2f2;
            font-weight: bold;
        }
        
        .list_table tr:nth-child(even) {
            background-color: #f9f9f9;
        }
        
        .list_table tr:hover {
            background-color: #f1f1f1;
        }
        
        /* 状态样式 */
        .status_normal {
            color: #28a745;
            font-weight: bold;
        }
        
        .status_frozen {
            color: #ffc107;
            font-weight: bold;
        }
        
        .status_blacklist {
            color: #dc3545;
            font-weight: bold;
        }
        
        /* 按钮样式 */
        .btn_freeze, .btn_unfreeze, .btn_blacklist, .btn_remove_blacklist, .btn_delete {
            display: inline-block;
            padding: 5px 10px;
            margin: 0 3px;
            border-radius: 3px;
            text-decoration: none;
            font-size: 12px;
        }
        
        .btn_freeze {
            background-color: #ffc107;
            color: #000;
        }
        
        .btn_unfreeze {
            background-color: #28a745;
            color: #fff;
        }
        
        .btn_blacklist {
            background-color: #dc3545;
            color: #fff;
        }
        
        .btn_remove_blacklist {
            background-color: #17a2b8;
            color: #fff;
        }
        
        .btn_delete {
            background-color: #6c757d;
            color: #fff;
        }
        
        /* 分页样式 */
        .pagination {
            margin-top: 20px;
            text-align: center;
        }
        
        .pagination a, .pagination span {
            display: inline-block;
            padding: 8px 12px;
            margin: 0 5px;
            border: 1px solid #ddd;
            border-radius: 3px;
            text-decoration: none;
            color: #333;
        }
        
        .pagination a:hover {
            background-color: #f1f1f1;
        }
        
        .pagination .page_current {
            background-color: #007bff;
            color: #fff;
            border-color: #007bff;
        }
    </style>
    <script type="text/javascript">
        // 冻结用户
        function freezeUser(userId) {
            if (confirm('确定要冻结该用户吗？')) {
                window.location.href = '/admin/user/freeze?id=' + userId;
            }
        }
        
        // 解冻用户
        function unfreezeUser(userId) {
            if (confirm('确定要解冻该用户吗？')) {
                window.location.href = '/admin/user/unfreeze?id=' + userId;
            }
        }
        
        // 加入黑名单
        function addToBlacklist(userId) {
            if (confirm('确定要将该用户加入黑名单吗？')) {
                window.location.href = '/admin/user/blacklist/add?id=' + userId;
            }
        }
        
        // 移除黑名单
        function removeFromBlacklist(userId) {
            if (confirm('确定要将该用户从黑名单中移除吗？')) {
                window.location.href = '/admin/user/blacklist/remove?id=' + userId;
            }
        }
        
        // 删除用户
        function deleteUser(userId) {
            if (confirm('确定要删除该用户吗？此操作不可恢复！')) {
                window.location.href = '/admin/user/delete?id=' + userId;
            }
        }
    </script>
</head>
<body>
<div class="container">
    <div id="header">
        <div class="logo">
            <a href=""><img src="images/admin/logo.png" width="303" height="43" /></a>
        </div>
        <p>
            <a href="/admin/logout">退出管理</a> <a href="/admin">后台首页</a> <a href="/" target='_blank'>商城首页</a>
            <span>您好 <label class='bold'>${sessionScope.manager.account}</label></span>
        </p>
    </div>

    <div id="admin_left">
        <ul class="submenu">
            <ul class="menu">
                <li><a href="admin/category/add">增加类别</a></li>
                <li><a href="admin/category/list">类别列表</a></li>
                <li><a href="admin/goods/add">增加商品</a></li>
<li><a href="admin/user/list">用户列表</a></li>
                
            </ul>
        </ul>
        <div id="copyright"></div>
    </div>

    <div id="admin_right">
        <div class="content_box">
            <!-- 用户列表 -->
            <div class="content">
                <div class="title">
                    <h2>用户列表</h2>
                </div>
                
                <!-- 搜索表单 -->
                <div class="search_form">
                    <form action="/admin/user/list" method="get">
                        <table class="form_table" cellpadding="0" cellspacing="0">
                            <tr>
                                <th>账号：</th>
                                <td><input class="normal" name="account" type="text" value="${param.account}"></td>
                                <th>邮箱：</th>
                                <td><input class="normal" name="email" type="text" value="${param.email}"></td>
                                <th>电话：</th>
                                <td><input class="normal" name="telephone" type="text" value="${param.telephone}"></td>
                                <td>
                                    <button class="submit" type="submit">
                                        <span>搜索</span>
                                    </button>
                                </td>
                            </tr>
                        </table>
                    </form>
                </div>
                
                <!-- 用户列表表格 -->
                <div class="list_table">
                    <table cellpadding="0" cellspacing="0">
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>账号</th>
                                <th>邮箱</th>
                                <th>电话</th>
                                <th>状态</th>
                                <th>黑名单</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            <!-- 使用静态假数据替代JSTL循环 -->
                            <c:forEach items="${userlist}" var="user">


                            <tr>
                                <td>${user.id}</td>
                                <td>${user.account}</td>
                                <td>${user.email}</td>
                                <td>${user.telphone}</td>
                                <td>
                                    <c:choose>
                                        <c:when test="${user.status == '0'}">
                                            <span class="status_normal">正常</span>
                                        </c:when>
                                        <c:when test="${user.status == '1'}">
                                            <span class="status_normal">已登录</span>
                                        </c:when>
                                        <c:when test="${user.status == '2'}">
                                            <span class="status_frozen">已冻结</span>
                                        </c:when>
                                        <c:when test="${user.status == '3'}">
                                            <span class="status_blacklist">黑名单</span>
                                        </c:when>
                                        <c:otherwise>
                                            <span class="status_normal">${user.status}</span>
                                        </c:otherwise>
                                    </c:choose>
                                </td>
                                <td>
                                    <c:choose>
                                        <c:when test="${user.status == '3'}">
                                            <span class="status_blacklist">是</span>
                                        </c:when>
                                        <c:otherwise>
                                            <span class="status_normal">否</span>
                                        </c:otherwise>
                                    </c:choose>
                                </td>
                                <td>
                                    <c:choose>
                                        <c:when test="${user.status == '2'}">
                                            <a href="javascript:void(0);" onclick="unfreezeUser(${user.id})" class="btn_unfreeze">解冻</a>
                                        </c:when>
                                        <c:when test="${user.status != '2' && user.status != '3'}">
                                            <a href="javascript:void(0);" onclick="freezeUser(${user.id})" class="btn_freeze">冻结</a>
                                        </c:when>
                                    </c:choose>
                                    
                                    <c:choose>
                                        <c:when test="${user.status == '3'}">
                                            <a href="javascript:void(0);" onclick="removeFromBlacklist(${user.id})" class="btn_remove_blacklist">移除黑名单</a>
                                        </c:when>
                                        <c:when test="${user.status != '3'}">
                                            <a href="javascript:void(0);" onclick="addToBlacklist(${user.id})" class="btn_blacklist">加入黑名单</a>
                                        </c:when>
                                    </c:choose>
                                    
                                    <a href="javascript:void(0);" onclick="deleteUser(${user.id})" class="btn_delete">删除</a>
                                </td>
                            </tr>
                            </c:forEach>

                        </tbody>
                    </table>
                </div>
                
                <!-- 分页 -->
                <div class="pagination">
                    <a href="/admin/user/list?page=1" class="page_prev">上一页</a>
                    
                    <a href="/admin/user/list?page=1" class="page_num">1</a>
                    <span class="page_current">2</span>
                    <a href="/admin/user/list?page=3" class="page_num">3</a>
                    <a href="/admin/user/list?page=4" class="page_num">4</a>
                    <a href="/admin/user/list?page=5" class="page_num">5</a>
                    
                    <a href="/admin/user/list?page=3" class="page_next">下一页</a>
                </div>
            </div>
        </div>
    </div>
    <div id="separator"></div>
</div>
</body>
</html>
